package com.ziyucoding.springboot.labs.lab10.seatdemo.tccscfeign.orderservice.dao;

import com.ziyucoding.springboot.labs.lab10.seatdemo.tccscfeign.orderservice.dataobject.OrderDO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

/**
 * 订单 DAO
 *
 * @author ziyucoding
 * @date 2022-11-04
 **/
@Mapper
@Repository
public interface OrderDao {

    /**
     * 保存订单
     *
     * @param order
     * @return
     */
    @Insert("INSERT INTO orders (user_id, product_id, pay_amount, status) VALUES (#{userId}, #{productId}, #{payAmount}, #{status})")
    @Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id")
    int saveOrder(OrderDO order);

    /**
     * 修改订单状态
     *
     * @param order
     * @return
     */
    @Update("update orders set status = #{status} where id = #{id}")
    int updateOrderStatus(OrderDO order);

    /**
     * 根据ID查询订单信息
     *
     * @param id
     * @return OrderDO
     **/
    @Select("SELECT id, user_id, product_id, pay_amount, status FROM orders WHERE id = #{id}")
    OrderDO findById(Integer id);
}
